﻿var list;
var site, web;
function ConfigTag() {

    var currentSite = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;
    var ctx = SP.ClientContext.get_current();
    web = ctx.get_web();
    site = ctx.get_site();
    ctx.load(site, 'Url');
    ctx.load(web);
    var listId = SP.ListOperation.Selection.getSelectedList();
    list = web.get_lists().getById(listId);
   ctx.load(list);
    ctx.executeQueryAsync(Function.createDelegate(this, this.onSuccessDelegate), Function.createDelegate(this, this.onFailDelegate));
    }
    function onSuccessDelegate(sender, args) {
        var currentPageUrl = web.get_serverRelativeUrl();
        var pageurl = site.get_url() + "/_layouts/P3.Modules.SharePoint.AutoTag/AutomaticTaggingConfig.aspx?SiteUrl=" + currentPageUrl + "&listID=" + list.get_id();

        var options = {
            url: pageurl,
            width: 700,
            dialogReturnValueCallback:           
            function () {
            
                window.location.href = window.location.href;
            }
        };

        SP.UI.ModalDialog.showModalDialog(options);
    }
    function onFailDelegate(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }